<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Zend_Service_WindowsAzure_Storage_Table - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.service.windowsazure.storage.table.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.service.windowsazure.storage.table.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.service.windowsazure.storage.queue.html">Zend_Service_WindowsAzure_Storage_Queue</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.service.html">Zend_Service</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.service.yahoo.html">Zend_Service_Yahoo</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.service.windowsazure.storage.table" class="section"><div class="info"><h1 class="title">Zend_Service_WindowsAzure_Storage_Table</h1></div>
    

    <p class="para">
        The Table service offers structured storage in the form of tables.
    </p>

    <p class="para">
        Table Storage is offered by Windows Azure as a REST <acronym class="acronym">API</acronym> which is wrapped
        by the <span class="classname">Zend_Service_WindowsAzure_Storage_Table</span> class in order to
        provide a native <acronym class="acronym">PHP</acronym> interface to the storage account.
    </p>

    <p class="para">
        This topic lists some examples of using the
        <span class="classname">Zend_Service_WindowsAzure_Storage_Table</span> class. Other features are
        available in the download package, as well as a detailed <acronym class="acronym">API</acronym>
        documentation of those features.
    </p>

    <p class="para">
        Note that development table storage (in the Windows Azure <acronym class="acronym">SDK</acronym>) does not
        support all features provided by the <acronym class="acronym">API</acronym>. Therefore, the examples listed
        on this page are to be used on Windows Azure production table storage.
    </p>

    <div class="section" id="zend.service.windowsazure.storage.table.api"><div class="info"><h1 class="title">Operations on tables</h1></div>
        

        <p class="para">
            This topic lists some samples of operations that can be executed on tables.
        </p>

        <div class="section" id="zend.service.windowsazure.storage.table.api.create"><div class="info"><h1 class="title">Creating a table</h1></div>
            

            <p class="para">
                Using the following code, a table can be created on Windows Azure production table
                storage.
            </p>

            <div class="example" id="zend.service.windowsazure.storage.table.api.create.example"><div class="info"><p><b>Example #1 Creating a table</b></p></div>
                

                <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Table(
    &#039;table.core.windows.net&#039;, &#039;myaccount&#039;, &#039;myauthkey&#039;
);
$result = $storageClient-&gt;createTable(&#039;testtable&#039;);

echo &#039;New table name is: &#039; . $result-&gt;Name;
</pre>

            </div>
        </div>

        <div class="section" id="zend.service.windowsazure.storage.table.api.list"><div class="info"><h1 class="title">Listing all tables</h1></div>
            

            <p class="para">
                Using the following code, a list of all tables in Windows Azure production table
                storage can be queried.
            </p>

            <div class="example" id="zend.service.windowsazure.storage.table.api.list.example"><div class="info"><p><b>Example #2 Listing all tables</b></p></div>
                

                <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Table(
    &#039;table.core.windows.net&#039;, &#039;myaccount&#039;, &#039;myauthkey&#039;
);
$result = $storageClient-&gt;listTables();
foreach ($result as $table) {
    echo &#039;Table name is: &#039; . $table-&gt;Name . &quot;\r\n&quot;;
}
</pre>

            </div>
        </div>
    </div>

    <div class="section" id="zend.service.windowsazure.storage.table.entities"><div class="info"><h1 class="title">Operations on entities</h1></div>
        

        <p class="para">
            Tables store data as collections of entities. Entities are similar to rows. An entity
            has a primary key and a set of properties. A property is a named, typed-value pair,
            similar to a column.
        </p>

        <p class="para">
            The Table service does not enforce any schema for tables, so two entities in the same
            table may have different sets of properties. Developers may choose to enforce a schema
            on the client side. A table may contain any number of entities.
        </p>

        <p class="para">
            <span class="classname">Zend_Service_WindowsAzure_Storage_Table</span> provides 2 ways of
            working with entities:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    Enforced schema
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    No enforced schema
                </p>
            </li>
        </ul>

        <p class="para">
            All examples will make use of the following enforced schema class.
        </p>

        <div class="example" id="zend.service.windowsazure.storage.table.entities.schema"><div class="info"><p><b>Example #3 Enforced schema used in samples</b></p></div>
            

            <pre class="programlisting brush: php">
class SampleEntity extends Zend_Service_WindowsAzure_Storage_TableEntity
{
    /**
    * @azure Name
    */
    public $Name;

    /**
    * @azure Age Edm.Int64
    */
    public $Age;

    /**
    * @azure Visible Edm.Boolean
    */
    public $Visible = false;
}
</pre>

        </div>

        <p class="para">
            Note that if no schema class is passed into table storage methods,
            <span class="classname">Zend_Service_WindowsAzure_Storage_Table</span> automatically works with
            <span class="classname">Zend_Service_WindowsAzure_Storage_DynamicTableEntity</span>.
        </p>

        <div class="section" id="zend.service.windowsazure.storage.table.entities.enforced"><div class="info"><h1 class="title">Enforced schema entities</h1></div>
            

            <p class="para">
                To enforce a schema on the client side using the
                <span class="classname">Zend_Service_WindowsAzure_Storage_Table</span> class, you can create
                a class which inherits
                <span class="classname">Zend_Service_WindowsAzure_Storage_TableEntity</span>. This class
                provides some basic functionality for the
                <span class="classname">Zend_Service_WindowsAzure_Storage_Table</span> class to work with a
                client-side schema.
            </p>

            <p class="para">
                Base properties provided by
                <span class="classname">Zend_Service_WindowsAzure_Storage_TableEntity</span> are:
            </p>

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        PartitionKey (exposed through  <span class="methodname">getPartitionKey()</span> and
                         <span class="methodname">setPartitionKey()</span>)
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        RowKey (exposed through  <span class="methodname">getRowKey()</span> and
                         <span class="methodname">setRowKey()</span>)
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Timestamp (exposed through  <span class="methodname">getTimestamp()</span> and
                         <span class="methodname">setTimestamp()</span>)
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Etag value (exposed through  <span class="methodname">getEtag()</span> and
                         <span class="methodname">setEtag()</span>)
                    </p>
                </li>
            </ul>

            <p class="para">
                Here&#039;s a sample class inheriting
                <span class="classname">Zend_Service_WindowsAzure_Storage_TableEntity</span>:
            </p>

            <div class="example" id="zend.service.windowsazure.storage.table.entities.enforced.schema"><div class="info"><p><b>Example #4 Sample enforced schema class</b></p></div>
                

                <pre class="programlisting brush: php">
class SampleEntity extends Zend_Service_WindowsAzure_Storage_TableEntity
{
    /**
     * @azure Name
     */
    public $Name;

    /**
     * @azure Age Edm.Int64
     */
    public $Age;

    /**
     * @azure Visible Edm.Boolean
     */
    public $Visible = false;
}
</pre>

            </div>

            <p class="para">
                The <span class="classname">Zend_Service_WindowsAzure_Storage_Table</span> class will map
                any class inherited from
                <span class="classname">Zend_Service_WindowsAzure_Storage_TableEntity</span> to Windows
                Azure table storage entities with the correct data type and property name. All there
                is to storing a property in Windows Azure is adding a docblock comment to a public
                property or public getter/setter, in the following format:
            </p>

            <div class="example" id="zend.service.windowsazure.storage.table.entities.enforced.schema-property"><div class="info"><p><b>Example #5 Enforced property</b></p></div>
                

                <pre class="programlisting brush: php">
/**
 * @azure &lt;property name in Windows Azure&gt; &lt;optional property type&gt;
 */
public $&lt;property name in PHP&gt;;
</pre>

            </div>

            <p class="para">
                Let&#039;s see how to define a propety &quot;Age&quot; as an integer on Windows Azure table
                storage:
            </p>

            <div class="example" id="zend.service.windowsazure.storage.table.entities.enforced.schema-property-sample"><div class="info"><p><b>Example #6 Sample enforced property</b></p></div>
                

                <pre class="programlisting brush: php">
/**
 * @azure Age Edm.Int64
 */
public $Age;
</pre>

            </div>

            <p class="para">
                Note that a property does not necessarily have to be named the same on Windows Azure
                table storage. The Windows Azure table storage property name can be defined as well
                as the type.
            </p>

            <p class="para">
                The following data types are supported:
            </p>

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        <b><tt>Edm.Binary</tt></b> - An array of bytes up to 64 KB in size.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <b><tt>Edm.Boolean</tt></b> - A boolean value.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <b><tt>Edm.DateTime</tt></b> - A 64-bit value expressed as Coordinated
                        Universal Time (UTC). The supported DateTime range begins from 12:00
                        midnight, January 1, 1601 A.D. (C.E.), Coordinated Universal Time (UTC). The
                        range ends at December 31st, 9999.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <b><tt>Edm.Double</tt></b> - A 64-bit floating point value.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <b><tt>Edm.Guid</tt></b> - A 128-bit globally unique identifier.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <b><tt>Edm.Int32</tt></b> - A 32-bit integer.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <b><tt>Edm.Int64</tt></b> - A 64-bit integer.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <b><tt>Edm.String</tt></b> - A UTF-16-encoded value. String values may
                        be up to 64 KB in size.
                    </p>
                </li>
            </ul>
        </div>

        <div class="section" id="zend.service.windowsazure.storage.table.entities.dynamic"><div class="info"><h1 class="title">No enforced schema entities (a.k.a. DynamicEntity)</h1></div>
            

            <p class="para">
                To use the <span class="classname">Zend_Service_WindowsAzure_Storage_Table</span> class
                without defining a schema, you can make use of the
                <span class="classname">Zend_Service_WindowsAzure_Storage_DynamicTableEntity</span> class.
                This class inherits
                <span class="classname">Zend_Service_WindowsAzure_Storage_TableEntity</span> like an
                enforced schema class does, but contains additional logic to make it dynamic and not
                bound to a schema.
            </p>

            <p class="para">
                Base properties provided by
                <span class="classname">Zend_Service_WindowsAzure_Storage_DynamicTableEntity</span> are:
            </p>

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        PartitionKey (exposed through  <span class="methodname">getPartitionKey()</span> and
                         <span class="methodname">setPartitionKey()</span>)
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        RowKey (exposed through  <span class="methodname">getRowKey()</span> and
                         <span class="methodname">setRowKey()</span>)
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Timestamp (exposed through  <span class="methodname">getTimestamp()</span> and
                         <span class="methodname">setTimestamp()</span>)
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Etag value (exposed through  <span class="methodname">getEtag()</span> and
                         <span class="methodname">setEtag()</span>)
                    </p>
                </li>
            </ul>

            <p class="para">
                Other properties can be added on the fly. Their Windows Azure table storage type
                will be determined on-the-fly:
            </p>

            <div class="example" id="zend.service.windowsazure.storage.table.entities.dynamic.schema"><div class="info"><p><b>Example #7 
                    Dynamicaly adding properties to
                    Zend_Service_WindowsAzure_Storage_DynamicTableEntity
                </b></p></div>
                

                <pre class="programlisting brush: php">
$target = new Zend_Service_WindowsAzure_Storage_DynamicTableEntity(
    &#039;partition1&#039;, &#039;000001&#039;
);
$target-&gt;Name = &#039;Name&#039;; // Will add property &quot;Name&quot; of type &quot;Edm.String&quot;
$target-&gt;Age  = 25;     // Will add property &quot;Age&quot; of type &quot;Edm.Int32&quot;
</pre>

            </div>

            <p class="para">
                Optionally, a property type can be enforced:
            </p>

            <div class="example" id="zend.service.windowsazure.storage.table.entities.dynamic.schema-forcedproperties"><div class="info"><p><b>Example #8 
                    Forcing property types on Zend_Service_WindowsAzure_Storage_DynamicTableEntity
                </b></p></div>
                

                <pre class="programlisting brush: php">
$target = new Zend_Service_WindowsAzure_Storage_DynamicTableEntity(
    &#039;partition1&#039;, &#039;000001&#039;
);
$target-&gt;Name = &#039;Name&#039;; // Will add property &quot;Name&quot; of type &quot;Edm.String&quot;
$target-&gt;Age  = 25;     // Will add property &quot;Age&quot; of type &quot;Edm.Int32&quot;

// Change type of property &quot;Age&quot; to &quot;Edm.Int32&quot;:
$target-&gt;setAzurePropertyType(&#039;Age&#039;, &#039;Edm.Int64&#039;);
</pre>

            </div>

            <p class="para">
                The <span class="classname">Zend_Service_WindowsAzure_Storage_Table</span> class
                automatically works with
                <span class="classname">Zend_Service_WindowsAzure_Storage_TableEntity</span> if no specific
                class is passed into Table Storage methods.
            </p>
        </div>

        <div class="section" id="zend.service.windowsazure.storage.table.entities.api"><div class="info"><h1 class="title">Entities API examples</h1></div>
            

            <div class="section" id="zend.service.windowsazure.storage.table.entities.api.insert"><div class="info"><h1 class="title">Inserting an entity</h1></div>
                

                <p class="para">
                    Using the following code, an entity can be inserted into a table named
                    &quot;testtable&quot;. Note that the table has already been created before.
                </p>

                <div class="example" id="zend.service.windowsazure.storage.table.api.entities.insert.example"><div class="info"><p><b>Example #9 Inserting an entity</b></p></div>
                    

                    <pre class="programlisting brush: php">
$entity = new SampleEntity (&#039;partition1&#039;, &#039;row1&#039;);
$entity-&gt;FullName = &quot;Maarten&quot;;
$entity-&gt;Age = 25;
$entity-&gt;Visible = true;

$storageClient = new Zend_Service_WindowsAzure_Storage_Table(
    &#039;table.core.windows.net&#039;, &#039;myaccount&#039;, &#039;myauthkey&#039;
);
$result = $storageClient-&gt;insertEntity(&#039;testtable&#039;, $entity);

// Check the timestamp and etag of the newly inserted entity
echo &#039;Timestamp: &#039; . $result-&gt;getTimestamp() . &quot;\n&quot;;
echo &#039;Etag: &#039; . $result-&gt;getEtag() . &quot;\n&quot;;
</pre>

                </div>
            </div>

            <div class="section" id="zend.service.windowsazure.storage.table.entities.api.retrieve-by-id"><div class="info"><h1 class="title">Retrieving an entity by partition key and row key</h1></div>
                

                <p class="para">
                    Using the following code, an entity can be retrieved by partition key and row
                    key. Note that the table and entity have already been created before.
                </p>

                <div class="example" id="zend.service.windowsazure.storage.table.entities.api.retrieve-by-id.example"><div class="info"><p><b>Example #10 Retrieving an entity by partition key and row key</b></p></div>
                    

                    <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Table(
    &#039;table.core.windows.net&#039;, &#039;myaccount&#039;, &#039;myauthkey&#039;
);
$entity= $storageClient-&gt;retrieveEntityById(
    &#039;testtable&#039;, &#039;partition1&#039;, &#039;row1&#039;, &#039;SampleEntity&#039;
);
</pre>

                </div>
            </div>

            <div class="section" id="zend.service.windowsazure.storage.table.entities.api.updating"><div class="info"><h1 class="title">Updating an entity</h1></div>
                

                <p class="para">
                    Using the following code, an entity can be updated. Note that the table and
                    entity have already been created before.
                </p>

                <div class="example" id="zend.service.windowsazure.storage.table.api.entities.updating.example"><div class="info"><p><b>Example #11 Updating an entity</b></p></div>
                    

                    <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Table(
    &#039;table.core.windows.net&#039;, &#039;myaccount&#039;, &#039;myauthkey&#039;
);
$entity = $storageClient-&gt;retrieveEntityById(
    &#039;testtable&#039;, &#039;partition1&#039;, &#039;row1&#039;, &#039;SampleEntity&#039;
);

$entity-&gt;Name = &#039;New name&#039;;
$result = $storageClient-&gt;updateEntity(&#039;testtable&#039;, $entity);
</pre>

                </div>

                <p class="para">
                    If you want to make sure the entity has not been updated before, you can make
                    sure the <acronym class="acronym">Etag</acronym> of the entity is checked. If the entity already
                    has had an update, the update will fail to make sure you do not overwrite any
                    newer data.
                </p>

                <div class="example" id="zend.service.windowsazure.storage.table.entities.api.updating.example-etag"><div class="info"><p><b>Example #12 Updating an entity (with Etag check)</b></p></div>
                    

                    <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Table(
    &#039;table.core.windows.net&#039;, &#039;myaccount&#039;, &#039;myauthkey&#039;
);
$entity = $storageClient-&gt;retrieveEntityById(
    &#039;testtable&#039;, &#039;partition1&#039;, &#039;row1&#039;, &#039;SampleEntity&#039;
);

$entity-&gt;Name = &#039;New name&#039;;

// last parameter instructs the Etag check:
$result = $storageClient-&gt;updateEntity(&#039;testtable&#039;, $entity, true);
</pre>

                </div>
            </div>

            <div class="section" id="zend.service.windowsazure.storage.table.entities.api.delete"><div class="info"><h1 class="title">Deleting an entity</h1></div>
                

                <p class="para">
                    Using the following code, an entity can be deleted. Note that the table and
                    entity have already been created before.
                </p>

                <div class="example" id="zend.service.windowsazure.storage.table.entities.api.delete.example"><div class="info"><p><b>Example #13 Deleting an entity</b></p></div>
                    

                    <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Table(
    &#039;table.core.windows.net&#039;, &#039;myaccount&#039;, &#039;myauthkey&#039;
);
$entity = $storageClient-&gt;retrieveEntityById(
    &#039;testtable&#039;, &#039;partition1&#039;, &#039;row1&#039;, &#039;SampleEntity&#039;
);
$result = $storageClient-&gt;deleteEntity(&#039;testtable&#039;, $entity);
</pre>

                </div>
            </div>
        </div>

        <div class="section" id="zend.service.windowsazure.storage.table.entities.querying"><div class="info"><h1 class="title">Performing queries</h1></div>
            

            <p class="para">
                Queries in <span class="classname">Zend_Service_WindowsAzure_Storage_Table</span> table
                storage can be performed in two ways:
            </p>

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        By manually creating a filter condition (involving learning a new query
                        language)
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        By using the fluent interface provided by the
                        <span class="classname">Zend_Service_WindowsAzure_Storage_Table</span>
                    </p>
                </li>
            </ul>

            <p class="para">
                Using the following code, a table can be queried using a filter condition. Note
                that the table and entities have already been created before.
            </p>

            <div class="example" id="zend.service.windowsazure.storage.table.entities.querying.query-filter"><div class="info"><p><b>Example #14 Performing queries using a filter condition</b></p></div>
                

                <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Table(
    &#039;table.core.windows.net&#039;, &#039;myaccount&#039;, &#039;myauthkey&#039;
);
$entities = $storageClient-&gt;storageClient-&gt;retrieveEntities(
    &#039;testtable&#039;,
    &#039;Name eq \&#039;Maarten\&#039; and PartitionKey eq \&#039;partition1\&#039;&#039;,
    &#039;SampleEntity&#039;
);

foreach ($entities as $entity) {
    echo &#039;Name: &#039; . $entity-&gt;Name . &quot;\n&quot;;
}
</pre>

            </div>

            <p class="para">
                Using the following code, a table can be queried using a fluent interface. Note
                that the table and entities have already been created before.
            </p>

            <div class="example" id="zend.service.windowsazure.storage.table.api.entities.query-fluent"><div class="info"><p><b>Example #15 Performing queries using a fluent interface</b></p></div>
                

                <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Table(
    &#039;table.core.windows.net&#039;, &#039;myaccount&#039;, &#039;myauthkey&#039;
);
$entities = $storageClient-&gt;storageClient-&gt;retrieveEntities(
    &#039;testtable&#039;,
    $storageClient-&gt;select()
                  -&gt;from($tableName)
                  -&gt;where(&#039;Name eq ?&#039;, &#039;Maarten&#039;)
                  -&gt;andWhere(&#039;PartitionKey eq ?&#039;, &#039;partition1&#039;),
    &#039;SampleEntity&#039;
);

foreach ($entities as $entity) {
    echo &#039;Name: &#039; . $entity-&gt;Name . &quot;\n&quot;;
}
</pre>

            </div>
        </div>

        <div class="section" id="zend.service.windowsazure.storage.table.entities.batch"><div class="info"><h1 class="title">Batch operations</h1></div>
            

            <p class="para">
                This topic demonstrates how to use the table entity group transaction features
                provided by Windows Azure table storage. Windows Azure table storage supports batch
                transactions on entities that are in the same table and belong to the same partition
                group. A transaction can include at most 100 entities.
            </p>

            <p class="para">
                The following example uses a batch operation (transaction) to insert a set of
                entities into the &quot;testtable&quot; table. Note that the table has already been created
                before.
            </p>

            <div class="example" id="zend.service.windowsazure.storage.table.api.batch"><div class="info"><p><b>Example #16 Executing a batch operation</b></p></div>
                

                <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Table(
    &#039;table.core.windows.net&#039;, &#039;myaccount&#039;, &#039;myauthkey&#039;
);

// Start batch
$batch = $storageClient-&gt;startBatch();

// Insert entities in batch
$entities = generateEntities();
foreach ($entities as $entity) {
    $storageClient-&gt;insertEntity($tableName, $entity);
}

// Commit
$batch-&gt;commit();
</pre>

            </div>
        </div>
    </div>

    <div class="section" id="zend.service.windowsazure.storage.table.sessionhandler"><div class="info"><h1 class="title">Table storage session handler</h1></div>
        

        <p class="para">
            When running a <acronym class="acronym">PHP</acronym> application on the Windows Azure platform in a
            load-balanced mode (running 2 Web Role instances or more), it is important that
            <acronym class="acronym">PHP</acronym> session data can be shared between multiple Web Role instances.
            The Windows Azure <acronym class="acronym">SDK</acronym> for <acronym class="acronym">PHP</acronym> provides the
            <span class="classname">Zend_Service_WindowsAzure_SessionHandler</span> class, which uses
            Windows Azure Table Storage as a session handler for <acronym class="acronym">PHP</acronym>
            applications.
        </p>

        <p class="para">
            To use the <span class="classname">Zend_Service_WindowsAzure_SessionHandler</span> session
            handler, it should be registered as the default session handler for your
            <acronym class="acronym">PHP</acronym> application:
        </p>

        <div class="example" id="zend.service.windowsazure.storage.table.api.sessionhandler-register"><div class="info"><p><b>Example #17 Registering table storage session handler</b></p></div>
            

            <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Table(
    &#039;table.core.windows.net&#039;, &#039;myaccount&#039;, &#039;myauthkey&#039;
);

$sessionHandler = new Zend_Service_WindowsAzure_SessionHandler(
    $storageClient , &#039;sessionstable&#039;
);
$sessionHandler-&gt;register();
</pre>

        </div>

        <p class="para">
            The above classname registers the
            <span class="classname">Zend_Service_WindowsAzure_SessionHandler</span> session handler and will
            store sessions in a table called &quot;sessionstable&quot;.
        </p>

        <p class="para">
            After registration of the
            <span class="classname">Zend_Service_WindowsAzure_SessionHandler</span> session handler,
            sessions can be started and used in the same way as a normal <acronym class="acronym">PHP</acronym>
            session:
        </p>

        <div class="example" id="zend.service.windowsazure.storage.table.api.sessionhandler-usage"><div class="info"><p><b>Example #18 Using table storage session handler</b></p></div>
            

            <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Table(
    &#039;table.core.windows.net&#039;, &#039;myaccount&#039;, &#039;myauthkey&#039;
);

$sessionHandler = new Zend_Service_WindowsAzure_SessionHandler(
    $storageClient , &#039;sessionstable&#039;
);
$sessionHandler-&gt;register();

session_start();

if (!isset($_SESSION[&#039;firstVisit&#039;])) {
    $_SESSION[&#039;firstVisit&#039;] = time();
}

// ...
</pre>

        </div>

        <div class="warning"><b class="warning">Warning</b>
            <p class="para">
                The <span class="classname">Zend_Service_WindowsAzure_SessionHandler</span> session handler
                should be registered before a call to  <span class="methodname">session_start()</span>
                is made!
            </p>
        </div>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.service.windowsazure.storage.queue.html">Zend_Service_WindowsAzure_Storage_Queue</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.service.html">Zend_Service</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.service.yahoo.html">Zend_Service_Yahoo</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.service.html">Zend_Service</a></li>
  <li><a href="zend.service.introduction.html">Introduction</a></li>
  <li><a href="zend.service.akismet.html">Zend_Service_Akismet</a></li>
  <li><a href="zend.service.amazon.html">Zend_Service_Amazon</a></li>
  <li><a href="zend.service.amazon.ec2.html">Zend_Service_Amazon_Ec2</a></li>
  <li><a href="zend.service.amazon.ec2.instance.html">Zend_Service_Amazon_Ec2: Instances</a></li>
  <li><a href="zend.service.amazon.ec2.windows.instance.html">Zend_Service_Amazon_Ec2: Windows Instances</a></li>
  <li><a href="zend.service.amazon.ec2.reserved.instance.html">Zend_Service_Amazon_Ec2: Reserved Instances</a></li>
  <li><a href="zend.service.amazon.ec2.cloudwatch.html">Zend_Service_Amazon_Ec2: CloudWatch Monitoring</a></li>
  <li><a href="zend.service.amazon.ec2.images.html">Zend_Service_Amazon_Ec2: Amazon Machine Images (AMI)</a></li>
  <li><a href="zend.service.amazon.ec2.ebs.html">Zend_Service_Amazon_Ec2: Elastic Block Storage (EBS)</a></li>
  <li><a href="zend.service.amazon.ec2.elasticip.html">Zend_Service_Amazon_Ec2: Elastic IP Addresses</a></li>
  <li><a href="zend.service.amazon.ec2.keypairs.html">Zend_Service_Amazon_Ec2: Keypairs</a></li>
  <li><a href="zend.service.amazon.ec2.zones.html">Zend_Service_Amazon_Ec2: Regions and Availability Zones</a></li>
  <li><a href="zend.service.amazon.ec2.securitygroups.html">Zend_Service_Amazon_Ec2: Security Groups</a></li>
  <li><a href="zend.service.amazon.s3.html">Zend_Service_Amazon_S3</a></li>
  <li><a href="zend.service.amazon.sqs.html">Zend_Service_Amazon_Sqs</a></li>
  <li><a href="zend.service.audioscrobbler.html">Zend_Service_Audioscrobbler</a></li>
  <li><a href="zend.service.delicious.html">Zend_Service_Delicious</a></li>
  <li><a href="zend.service.developergarden.html">Zend_Service_DeveloperGarden</a></li>
  <li><a href="zend.service.ebay.html">Zend_Service_Ebay</a></li>
  <li><a href="zend.service.ebay.finding.html">Zend_Service_Ebay_Finding</a></li>
  <li><a href="zend.service.flickr.html">Zend_Service_Flickr</a></li>
  <li><a href="zend.service.livedocx.html">Zend_Service_LiveDocx</a></li>
  <li><a href="zend.service.nirvanix.html">Zend_Service_Nirvanix</a></li>
  <li><a href="zend.service.recaptcha.html">Zend_Service_ReCaptcha</a></li>
  <li><a href="zend.service.short-url.html">Zend_Service_ShortUrl</a></li>
  <li><a href="zend.service.simpy.html">Zend_Service_Simpy</a></li>
  <li><a href="zend.service.slideshare.html">Zend_Service_SlideShare</a></li>
  <li><a href="zend.service.strikeiron.html">Zend_Service_StrikeIron</a></li>
  <li><a href="zend.service.strikeiron.bundled-services.html">Zend_Service_StrikeIron: Bundled Services</a></li>
  <li><a href="zend.service.strikeiron.advanced-uses.html">Zend_Service_StrikeIron: Advanced Uses</a></li>
  <li><a href="zend.service.technorati.html">Zend_Service_Technorati</a></li>
  <li><a href="zend.service.twitter.html">Zend_Service_Twitter</a></li>
  <li><a href="zend.service.windowsazure.html">Zend_Service_WindowsAzure</a></li>
  <li><a href="zend.service.windowsazure.storage.blob.html">Zend_Service_WindowsAzure_Storage_Blob</a></li>
  <li><a href="zend.service.windowsazure.diagnostics.manager.html">Zend_Service_WindowsAzure_Diagnostics_Manager</a></li>
  <li><a href="zend.service.windowsazure.storage.queue.html">Zend_Service_WindowsAzure_Storage_Queue</a></li>
  <li class="active"><a href="zend.service.windowsazure.storage.table.html">Zend_Service_WindowsAzure_Storage_Table</a></li>
  <li><a href="zend.service.yahoo.html">Zend_Service_Yahoo</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>